package com.fowo.api.syncAmazon.controller;

import com.fowo.api.entity.TmpFbaShipment;
import com.fowo.api.entity.TmpFbaShipmentProduct;
import com.fowo.api.syncAmazon.api.FbaOutboundApiService;
import com.fowo.api.syncAmazon.api.OrderService;
import com.fowo.api.syncAmazon.api.ReimbursementsReportService;
import com.fowo.api.syncAmazon.api.ShipmentService;
import com.fowo.api.syncAmazon.entity.TmpSellOrder;
import com.fowo.api.syncAmazon.service.impl.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sync/amazon")
public class SyncAmazonController {

    @Resource
    private OrderService orderService;
    @Resource
    private TmpSellOrderServiceImpl tmpSellOrderService;

    @Resource
    private ShipmentService shipmentService;
    @Resource
    private TmpFbaShipmentAmazonServiceImpl shipmentAmazonService;
    @Resource
    private TmpFbaShipmentProductAmazonServiceImpl productAmazonService;
    @Resource
    private StorageFeeMonthServiceImpl service;
    @Resource
    private StorageFeeLongTermServiceImpl termService;
    @Resource
    private RefundOrdersReportServiceImpl reportService;
    @Resource
    private RemoveOrderServiceImpl removeOrderService;
    @Resource
    private ExchangeOrderServiceImpl exchangeOrderService;
    @Resource
    private RemoveShipmentServiceImpl removeShipmentService;
    @Resource
    private FbaOutboundApiService fbaOutboundApiService;

    @PostMapping("/getOrder")
    public void insertOrder() {
        try {
            List<TmpSellOrder> order = orderService.getOrder();
            tmpSellOrderService.save(order);
        } catch (Exception e) {
        }
    }

    @PostMapping("/getFba")
    public void insertFba() {
        try {
            List<TmpFbaShipment> shipments = shipmentService.getShipments();
            shipmentAmazonService.save(shipments);
        } catch (Exception e) {
            log.info(e.getMessage());
        }

    }

    @PostMapping("/getItem")
    public void insertShipmentProduct() {
        try {
            List<TmpFbaShipmentProduct> shipmentItems = shipmentService.getShipmentItems();
            productAmazonService.saveItem(shipmentItems);
        } catch (Exception e) {
            log.info(String.valueOf(e));
        }
    }

    @PostMapping("/getFeeMonth")
    public void insertFeeMonth() {
        try {
            service.syncStorageFeeMonth();
        } catch (Exception e) {
            log.info(e.getMessage());
        }
    }

    @PostMapping("/getFeeLong")
    public void getFeeLong() {
        try {
            termService.syncStorageFeeLongTerm();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/getRefund")
    public void getRefundOrder() {
        try {
            reportService.syncRefundOrders();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/getRemove")
    public void getRemoveOrder() {
        try {
            removeOrderService.syncRemoveOrder();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/getExchange")
    public void getExchange() {
        try {
            exchangeOrderService.syncExchangeOrder();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/getShipment")
    public void getRemoveShipment() {
        try {
            removeShipmentService.syncRemoveShipment();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/orderReport")
    public void getOrderReport() {
        try {
            orderService.getOrderReport();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
